Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: avoid TypeError on not: {not: {anyOf: [...]}}. #141

Merged
merged 1 commit into from
Feb 5, 2025

Conversation

myronmarston
Copy link
Collaborator

We have special handling for double nots to "pull up" the filter clauses for greater efficiency. That handling didn't work right when an anyOf was under the double not, and we got a TypeError:

TypeError: no implicit conversion of Integer into Array
  from elastic_graph/graphql/filtering/filter_interpreter.rb:121:in `concat'
  from elastic_graph/graphql/filtering/filter_interpreter.rb:121:in `block (2 levels) in process_not_expression'
  from elastic_graph/graphql/filtering/filter_interpreter.rb:121:in `each'
  from elastic_graph/graphql/filtering/filter_interpreter.rb:121:in `block in process_not_expression'
  from elastic_graph/graphql/filtering/filter_interpreter.rb:120:in `each'
  from elastic_graph/graphql/filtering/filter_interpreter.rb:120:in `process_not_expression'
  from elastic_graph/graphql/filtering/filter_interpreter.rb:66:in `block in process_filter_hash'
  from elastic_graph/graphql/filtering/filter_interpreter.rb:61:in `each'
  from elastic_graph/graphql/filtering/filter_interpreter.rb:61:in `process_filter_hash'
  from elastic_graph/graphql/filtering/filter_interpreter.rb:43:in `block (2 levels) in build_query'
  from set.rb:511:in `each_key'
  from set.rb:511:in `each'
  from elastic_graph/graphql/filtering/filter_interpreter.rb:42:in `block in build_query'
  from <internal:kernel>:90:in `tap'
  from elastic_graph/graphql/filtering/filter_interpreter.rb:337:in `build_bool_hash'
  from elastic_graph/graphql/filtering/filter_interpreter.rb:41:in `build_query'
  from elastic_graph/graphql/datastore_query.rb:318:in `to_datastore_body'
  from elastic_graph/graphql/datastore_query.rb:229:in `empty?'
  from elastic_graph/graphql/datastore_query.rb:94:in `each'
  from elastic_graph/graphql/datastore_query.rb:94:in `partition'
  from elastic_graph/graphql/datastore_query.rb:94:in `perform'
  from elastic_graph/graphql/datastore_search_router.rb:34:in `msearch'
  from elastic_graph/graphql/resolvers/query_source.rb:26:in `fetch'
  from graphql/dataloader/source.rb:136:in `run_pending_keys'
  from graphql/dataloader.rb:294:in `block (2 levels) in spawn_source_fiber'
  from graphql/dataloader.rb:292:in `each'
  from graphql/dataloader.rb:292:in `block in spawn_source_fiber'
  from graphql/dataloader.rb:245:in `block in spawn_fiber'

This fixes that case.

We have special handling for double nots to "pull up" the filter
clauses for greater efficiency. That handling didn't work right
when an `anyOf` was under the double `not`, and we got a `TypeError`:

```
TypeError: no implicit conversion of Integer into Array
  from elastic_graph/graphql/filtering/filter_interpreter.rb:121:in `concat'
  from elastic_graph/graphql/filtering/filter_interpreter.rb:121:in `block (2 levels) in process_not_expression'
  from elastic_graph/graphql/filtering/filter_interpreter.rb:121:in `each'
  from elastic_graph/graphql/filtering/filter_interpreter.rb:121:in `block in process_not_expression'
  from elastic_graph/graphql/filtering/filter_interpreter.rb:120:in `each'
  from elastic_graph/graphql/filtering/filter_interpreter.rb:120:in `process_not_expression'
  from elastic_graph/graphql/filtering/filter_interpreter.rb:66:in `block in process_filter_hash'
  from elastic_graph/graphql/filtering/filter_interpreter.rb:61:in `each'
  from elastic_graph/graphql/filtering/filter_interpreter.rb:61:in `process_filter_hash'
  from elastic_graph/graphql/filtering/filter_interpreter.rb:43:in `block (2 levels) in build_query'
  from set.rb:511:in `each_key'
  from set.rb:511:in `each'
  from elastic_graph/graphql/filtering/filter_interpreter.rb:42:in `block in build_query'
  from <internal:kernel>:90:in `tap'
  from elastic_graph/graphql/filtering/filter_interpreter.rb:337:in `build_bool_hash'
  from elastic_graph/graphql/filtering/filter_interpreter.rb:41:in `build_query'
  from elastic_graph/graphql/datastore_query.rb:318:in `to_datastore_body'
  from elastic_graph/graphql/datastore_query.rb:229:in `empty?'
  from elastic_graph/graphql/datastore_query.rb:94:in `each'
  from elastic_graph/graphql/datastore_query.rb:94:in `partition'
  from elastic_graph/graphql/datastore_query.rb:94:in `perform'
  from elastic_graph/graphql/datastore_search_router.rb:34:in `msearch'
  from elastic_graph/graphql/resolvers/query_source.rb:26:in `fetch'
  from graphql/dataloader/source.rb:136:in `run_pending_keys'
  from graphql/dataloader.rb:294:in `block (2 levels) in spawn_source_fiber'
  from graphql/dataloader.rb:292:in `each'
  from graphql/dataloader.rb:292:in `block in spawn_source_fiber'
  from graphql/dataloader.rb:245:in `block in spawn_fiber'
```

This fixes that case.
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Collaborator

@BrianSigafoos-SQ BrianSigafoos-SQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@myronmarston myronmarston merged commit a29eefe into main Feb 5, 2025
18 of 19 checks passed
@myronmarston myronmarston deleted the myron/fix-TypeError branch February 5, 2025 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants